import 'package:flutter/material.dart';
import '/components/page/common.dart';
import '/components/list/route_menu_item.dart';
import 'package:wechat_assets_picker/wechat_assets_picker.dart';
import '/utils/permission.dart';

// 我的 - 个人信息页面
class PersonInfoPage extends StatelessWidget {
  final String title;
  const PersonInfoPage({
    super.key,
    required this.title,
  });

  @override
  Widget build(BuildContext context) {
    return CommonPage(
        title: title,
        child: const PersonInfoWidget()
    );
  }
}

// 个人信息 - 主组件内容
class PersonInfoWidget extends StatelessWidget {
  const PersonInfoWidget({super.key});

  @override
  Widget build(BuildContext context) {

    // 选择相册
    void handleOpenAlbum() async {
      final List<AssetEntity>? assets = await AssetPicker.pickAssets(
        context,
        pickerConfig: const AssetPickerConfig(
          maxAssets: 10, // 最多可以选择的资产数量
          requestType: RequestType.image, // 选择图片和视频
          textDelegate: AssetPickerTextDelegate(),
        ),
      );
      if (assets != null && assets.isNotEmpty) {
        // 处理选中的资产
        for (final asset in assets) {
          debugPrint('Selected asset: $asset');
        }
      }
    }

    List listData = [
      {
        'title': '前端没钱',
        'hasBottom': false,
        'rightImgPath': 'assets/images/lufei.png',
        'onTap': () async {
          debugPrint('选择照片');

          /// 是否已开启相册权限
          bool hasPermissionPhoto = await CheckPermission.photos();
          if (hasPermissionPhoto) {
            handleOpenAlbum();
          }
        }
      },
      {
        'title': '名字',
        'hasBottom': false,
        'rightText': '做门禁卡卡贴',
        // 'onTap': () {
        //   Navigator.pushNamed(context, 'WxChangeNamePage');
        // }
      },
      {
        'title': '拍一拍',
        'hasBottom': false,
        'rightText': '好好地',
      },
      {
        'title': '微信号',
        'hasBottom': false,
        'rightText': 'wx_id20240511789',
      },
      {
        'title': '二维码名片',
        'hasBottom': false,
        'rightIconName': Icons.qr_code,
      },
      {
        'title': '更多信息',
      },
      {
        'title': '来电铃声',
        'rightText': '背景声音',
      },
      {
        'title': '微信豆',
      },
      {
        'title': '我的地址',
        'hasBottom': false
      },
      {
        'title': '我的发票抬头',
      },
    ];

    return Column(
        children: listData.map((item) => RouteMenuItem(
          leftImgPath: item['leftImgPath'],
          title: item['title'],
          hasBottom: item['hasBottom'] ?? true,
          rightText: item['rightText'],
          rightImgPath: item['rightImgPath'],
          rightIconName: item['rightIconName'],
          // onTap: item['onTap'] == null ? () {
          //   Navigator.pushNamed(context, 'EmptyPage', arguments: {
          //     'title': item['title']
          //   });
          // } : () => item['onTap']!,
          onTap: item['onTap'],
        )).toList()
    );
  }
}
